export const useFloatWindow = defineStore('floatWindow', () => {
  /**
   * @typedef {Object} ChatWindow
   * @property {string} url
   * @property {string} appName
   * @property {string} icon
   */
  /**
   * @type {Ref<ChatWindow>}
   */
  const windows = ref([])
  const zIndex = ref(500)
  const miniWindows = computed(() => {
    return windows.value.filter((i) => i.mini)
  })

  function addWindow(win) {
    win.zIndex = zIndex.value++
    // 暂时只支持单窗口，后续考虑多窗口
    windows.value = [win]
  }

  function removeWindow(win) {
    windows.value.splice(windows.value.indexOf(win), 1)
  }

  function miniWindow(win) {
    win.mini = true
  }

  function restoreWindow(win) {
    win.mini = false
  }

  function fullWindow(win) {
    win.full = !win.full
  }

  function activeWindow(win) {
    win.active = zIndex.value++
  }

  return {
    windows,
    miniWindows,
    addWindow,
    removeWindow,
    miniWindow,
    fullWindow,
    restoreWindow,
    activeWindow,
  }
})
